package main

import (
	"fmt"
	"runtime"
	"sync"
)

func sentMessage(message string) {
	fmt.Println(message)
}

var COUNT int

func counter(lock *sync.Mutex) {
	lock.Lock()
	COUNT++
	fmt.Println(COUNT)
	lock.Unlock()
}
func main() {
	lock := new(sync.Mutex)
	for i := 0; i < 10; i++ {
		go counter(lock)
	}

	for {
		lock.Lock()
		c := COUNT
		lock.Unlock()
		///把时间片给别的goroutine  未来某个时刻运行该routine
		runtime.Gosched()
		if c >= 10 {
			fmt.Println("goroutine end")
			break
		}
	}
}
